﻿#region references
using System;
using System.Reflection;
using System.ComponentModel;
#endregion

namespace IcaGames.Objects
{
    /*
     * Enumeration to choose the Platform for a Game.
     * 
     * @enums
     * PC: Enum for PC GameType.
     * Xbox360: Enum for Xbox 360 GameType.
     * NintendoWii: Enum for Nintendo Wii GameType.
     * NintendoDS: Enum for Nintendo DS GameType.
     * Playstation2: Enum for Playstation 2 GameType.
     * Playstation3: Enum for Playstation 3 GameType.
     * PlaystationPortable: Enum for Playstation Portable GameType.
     */
    [Serializable]
    public enum Platform
    {
        PC=1,
        [Description("Xbox 360")]
        Xbox360=2,
        [Description("Nintento Wii")]
        NintendoWii=3,
        [Description("Nintendo DS")]
        NintendoDS=4,
        [Description("Playstation 2")]
        Playstation2=5,
        [Description("Playstation 3")]
        Playstation3=6,
        [Description("Playstation Portable")]
        PlaystationPortable=7
    }

    public static class PlatformDescription
    {
        /*
         * Function to get the Description for the specified Platform enum.
         * 
         * @param
         * pf: The specified Platform enum.
         * 
         * @returns
         * The description of the specified Platform enum.
         */
        public static string GetDescription(Platform pf)
        {
            FieldInfo fi = pf.GetType().GetField(pf.ToString());
            DescriptionAttribute[] da = (DescriptionAttribute[])fi.GetCustomAttributes(
                typeof(DescriptionAttribute), false);

            if (da.Length == 0) { return pf.ToString(); }
            else { return da[0].Description; }
        }
    }

    public static class PlatformValue
    {
        /*
         * Function to get the valye for the specified Platform description.
         * 
         * @param
         * description: The specified description.
         * 
         * @returns
         * The value of the specified Platform description.
         */
        public static int GetPlatformValue(string description)
        {
            switch (description)
            {
                case "PC":
                    return 1;
                case "Xbox360":
                    return 2;
                case "NintendoWii":
                    return 3;
                case "NintendoDS":
                    return 4;
                case "Playstation2":
                    return 5;
                case "Playstation3":
                    return 6;
                case "PlaystationPortable":
                    return 7;
                default:
                    return 1;
            }
        }

        /*
         * Function to get the Platform enum given a specified description.
         * 
         * @param
         * text: The description.
         * 
         * @returns
         * The Platform selected with the description.
         */
        public static Platform GetPlatform(string description)
        {
            switch (description)
            {
                case "PC":
                    return Platform.PC;
                case "Xbox360":
                    return Platform.Xbox360;
                case "NintendoWii":
                    return Platform.NintendoWii;
                case "NintendoDS":
                    return Platform.NintendoDS;
                case "Playstation2":
                    return Platform.Playstation2;
                case "Playstation3":
                    return Platform.Playstation3;
                case "PlaystationPortable":
                    return Platform.PlaystationPortable;
                default:
                    return Platform.PC;
            }
        }
    }
}
